package com.zzyl.member.job;

import com.zzyl.member.domain.Reservation;
import com.zzyl.member.mapper.ReservationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author 24029
 */
@Component
@Slf4j
public class ReservationExpireTask {

    @Autowired
    private ReservationMapper reservationMapper;


    /**
     * 定时任务处理预约过期(5分钟跑一次)
     */
    @Scheduled(cron = "0 */5 * * * ?")
    public void markExpiredReservations() {
        List<Reservation> expiredList = reservationMapper.findAndMarkExpired(LocalDateTime.now());

        if (!expiredList.isEmpty()) {
            log.info("标记过期预约 {} 条", expiredList.size());
        }
    }
}
